package com.holystone.orca.sys.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.holystone.orca.common.JSONMapper;
import com.holystone.orca.common.PageData;
import com.holystone.orca.sys.common.SystemConstant;
import com.holystone.orca.sys.model.StaffVO;
import com.holystone.orca.sys.service.ISysOperationLogService;
import com.holystone.orca.sys.service.ISysPersonService;
 
@Controller
@RequestMapping("/sys/operation_log")
public class SysOperationLogController {

	private static Logger logger = Logger.getLogger(SysOperationLogController.class);
	
	private String baseUrl = "sys/operation_log/";
		
	@Resource(name="sysOperationLogService")
	private ISysOperationLogService sysOperationLogService;
	
	@Resource(name="sysPersonService")
	private ISysPersonService sysPersonService;
	
    @RequestMapping("/menuOperationLog")
    public ModelAndView initOperationList(){
    	ModelAndView model = new ModelAndView(baseUrl+"operation_log");
        return model;
    }

    //分页，初始化用户页面
    @ResponseBody
    @RequestMapping("/pagingOperationLogList")
    public ModelMap pagingPersonList(String  iPageNo, String iPageSize,String personCode){
    	int pageindex = iPageNo!=null?Integer.parseInt(iPageNo):SystemConstant.default_pageNum;
        int pagesize = iPageSize!=null?Integer.parseInt(iPageSize):SystemConstant.default_pageSize;
        PageData pageData = new PageData();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("personCode", personCode);
        try{
            pageData = sysOperationLogService.pagingSysOperationLog(pageindex, pagesize,"log_id",map);
        }catch(Exception e){
            logger.error(e,e);
        }
        return JSONMapper.createReturnMap(null, pageData, null);
    }
    
    @ResponseBody
    @RequestMapping("/lookSysPerson")
    public ModelAndView lookSysPerson(String personCode,ModelMap modelMap){
    	StaffVO staffVO=null;
    	Map<Object,String> map = new HashMap<Object,String>();
    	map.put("personCode", personCode);
    	try {
    		staffVO = sysPersonService.selectStaffVOByPersonCode(map);
		} catch (Exception e) {
			 logger.error(e,e);
		}
    	ModelAndView model = new ModelAndView(baseUrl+"see_person");
    	modelMap.put("sysStaffVO", staffVO);
        return model;
    }
    
    
}